package top.tangyh.lamp.care.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.tangyh.basic.base.R;
import top.tangyh.basic.interfaces.echo.EchoService;
import top.tangyh.basic.base.controller.SuperController;
import top.tangyh.lamp.care.service.BObsvRecordService;
import top.tangyh.lamp.care.entity.BObsvRecord;
import top.tangyh.lamp.care.vo.query.*;
import top.tangyh.lamp.care.vo.result.ObsrvUseDaysDto;
import top.tangyh.lamp.care.vo.result.ObsvRecordQueryParam;
import top.tangyh.lamp.care.vo.save.BObsvRecordSaveVO;
import top.tangyh.lamp.care.vo.update.BObsvRecordUpdateVO;
import top.tangyh.lamp.care.vo.result.BObsvRecordResultVO;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 前端控制器
 * 观察项记录表
 * </p>
 *
 * @author zqb
 * @date 2024-07-24 15:47:49
 * @create [2024-07-24 15:47:49] [zqb] [代码生成器生成]
 */
@Slf4j
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/obsvRecord")
@Tag(name = "系统：观察项记录")
public class BObsvRecordController {

//    extends SuperController<BObsvRecordService, Long, BObsvRecord
//            , BObsvRecordSaveVO, BObsvRecordUpdateVO, BObsvRecordPageQuery, BObsvRecordResultVO>
//    private final EchoService echoService;
//    @Override
//    public EchoService getEchoService() {
//        return echoService;
//    }

    private final BObsvRecordService bObsvRecordService;


    @Operation(summary = "查询观察项记录")
    @GetMapping("/query")
    public R<List<BObsvRecordResultVO>> query(@Valid ObsvRecordQueryParam param) throws Exception {
        return R.success(bObsvRecordService.queryOld(param));
    }

//    @Operation(summary = "查询医生用观察项记录")
//    @GetMapping("/doctor/query")
//    public R<List<BObsvRecordResultVO>> queryByDoctor(@Valid ObsvRecordQueryByDoctorParam param) throws Exception {
//        return R.success(bObsvRecordService.queryByDoctor(param));
//    }


    @Operation(summary = "保存观察项记录")
    @PostMapping("/save")
    public R<Boolean> save(@Valid @RequestBody BObsvRecordSaveVO param) throws Exception {
        return R.success(bObsvRecordService.addAndUpdate(param));
    }

//    @Operation(summary = "测试是否未填记录")
//    @PostMapping("/hasAllVal")
//    public R<Boolean> hasAbllVal(@Valid @RequestBody ObsvRecordQueryParam param) throws Exception {
//        return R.success(bObsvRecordService.hasAllVal(param));
//    }
//
//    @Operation(summary = "测试使唤用呼吸机天数", description = "测试使唤用呼吸机天数")
//    @Parameters({
//            @Parameter(description = "病人识别号", required = true),
//            @Parameter(description = "交班日期，说明：时间戳", example = " ", required = true),
//    })
//    @GetMapping("/getUeDaysWithBreathe")
//    public R<Integer> getUeDaysWithBreathe(String patientIdent, Long changeShiftTime) throws Exception {
//        return R.success(bObsvRecordService.getUeDaysWithBreathe(patientIdent, changeShiftTime));
//    }


//    @Operation(summary = "测试获得天数")
//    @GetMapping("/getUeDays")
//    public R<ObsrvUseDaysDto> getUeDays(ObsrvUseDaysParam param) {
//        return R.success(bObsvRecordService.getDays(param));
//    }

    @PutMapping("/status")
    @Operation(summary = "更改该病人该时间点所有观察项的状态")
    public R updateRecordStatus(@RequestBody @Valid UpdateStatusDTO updateStatusDTO) {
        bObsvRecordService.updateRecordStatus(updateStatusDTO);
        return R.success();
    }


    @Operation(summary = "删除观察项记录")
    @DeleteMapping
    public R<Boolean> del(@RequestBody @Valid ObsvRecordCodesVO param) {
        return R.success(bObsvRecordService.del(param));
    }

//    @PutMapping("/update/caijiren")
//    @Operation(summary = "修改采集人名称")
//    public R updateCaijiren(@RequestBody @Valid CaijirenDto caijirenDto) {
//
//        return R.success(bObsvRecordService.updateCaijiren(caijirenDto));
//    }

//    @GetMapping("/record/switch")
//    @Operation(summary = "观察项是否显示开关")
//    public R<Integer> openOrClose(@Parameter(description = "住院号", required = true) @RequestParam String hospitalNumber,
//                                     @Parameter(description = "病人识别号", required = true) @RequestParam String patientIdent,
//                                     @Parameter(description = "操作类型 0 关  1 开", required = true)@RequestParam  Integer operation,
//                                     @Parameter(description = "操作时间") @RequestParam(required = true) Long operationTIme,
//                                     @Parameter(description = "观察项类型：生命体征 vs,呼吸 breathe") @RequestParam(required = true) String obsvType ) {
//        int result = bObsvRecordService.updateObsvRecordIsVisible( hospitalNumber, patientIdent,operation, operationTIme,obsvType);
//        return R.success(result);
//    }
//
//
//
//
//    @GetMapping("/record/switch/status")
//    @Operation(summary = "观察项是否显示开关的状态")
//    public R<List<ObsvRecordVisibleStatus>> isvisibleStatus(@Parameter(description = "住院号", required = true) @RequestParam String hospitalNumber,
//                                                               @Parameter(description = "操作时间") @RequestParam Long operationTIme) {
//        List<YxObsvRecord> list=bObsvRecordService.getRecodByTime(hospitalNumber,operationTIme);
//        //breathe
//        List<YxObsvRecord> listVs=list.stream().filter(e->e.getObsvType().equals("vs")).collect(Collectors.toList());
//        List<YxObsvRecord> listBreathe=list.stream().filter(e->e.getObsvType().equals("breathe")).collect(Collectors.toList());
//
//        List<ObsvRecordVisibleStatus> listResult=new ArrayList<>();
//
//        if(listVs.size()>0){
//            ObsvRecordVisibleStatus obsvRecordVisibleStatus=new ObsvRecordVisibleStatus();
//            obsvRecordVisibleStatus.setTypeName("vs");
//            obsvRecordVisibleStatus.setStatus(listVs.get(0).getIsVisible());
//            listResult.add(obsvRecordVisibleStatus);
//        }
//        if(listBreathe.size()>0){
//            ObsvRecordVisibleStatus obsvRecordVisibleStatus=new ObsvRecordVisibleStatus();
//            obsvRecordVisibleStatus.setTypeName("breathe");
//            obsvRecordVisibleStatus.setStatus(listBreathe.get(0).getIsVisible());
//            listResult.add(obsvRecordVisibleStatus);
//        }
//
//        return R.success(listResult);
//    }


}


